﻿using Resolve.Contracts;
using Resolve.FlagInfo;
using Resolve.Web;

namespace Resolve
{
    /// <summary>
    /// 编译目录
    /// </summary>
    public class ResolveEngineForFolder : ResolveEngineBase
    {
        /// <summary>
        /// 解析
        /// </summary>
        /// <param name="filePath">文件路径</param>
        /// <returns></returns>
        public override string Resolve(string filePath)
        {
            FilePath = filePath;
            CheckFilePath();
            FlagCodeInFile flagCodeInFile = CodeCompiler.CompileFloderFromFilePath(FilePath, ViewData, Model);
            if (flagCodeInFile.CompileObject != null)
            {
                ViewPageBase viewPageBase = (ViewPageBase)flagCodeInFile.CompileObject;
                //设置Layout数据
                if (!string.IsNullOrEmpty(viewPageBase.Layout))
                {
                    ViewPageBase viewPageBaseLayout = (ViewPageBase)viewPageBase.LayoutFlagCodeInFile.CompileObject;
                    viewPageBaseLayout.ViewData = ViewData;
                    viewPageBaseLayout.Model = Model;
                    viewPageBase.LayoutFlagCodeInFile.CompileObject = viewPageBaseLayout;
                }
            }
            HtmlGenerater.FlagCodeInFile = flagCodeInFile;
            string html = HtmlGenerater.Generate();
            return html;
        }
    }
}
